package com.basic.modules.ykf.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.basic.common.utils.ParamsModel;
import com.basic.common.utils.ParamUtils;
import com.basic.modules.ykf.entity.YkfCustomerShopEntity;
import com.basic.modules.ykf.service.YkfCustomerShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.basic.common.utils.PageUtils;
import com.basic.common.utils.Query;

import com.basic.modules.ykf.dao.YkfNotCheckRecordDao;
import com.basic.modules.ykf.entity.YkfNotCheckRecordEntity;
import com.basic.modules.ykf.service.YkfNotCheckRecordService;


@Service("ykfNotCheckRecordService")
public class YkfNotCheckRecordServiceImpl extends ServiceImpl<YkfNotCheckRecordDao, YkfNotCheckRecordEntity> implements YkfNotCheckRecordService {

    @Autowired
    private YkfCustomerShopService shopService;

    @Override
    public PageUtils queryPage(ParamsModel<YkfNotCheckRecordEntity> params) {
        QueryWrapper<YkfNotCheckRecordEntity> queryWrapper = ParamUtils.createQueryWrapperByDefaultSort(params);
        if (ObjectUtil.isNotEmpty(params.getCondition().getDateStart())) {
            queryWrapper.lambda().ge(YkfNotCheckRecordEntity::getDate, params.getCondition().getDateStart());
        }
        if (ObjectUtil.isNotEmpty(params.getCondition().getDateEnd())) {
            queryWrapper.lambda().le(YkfNotCheckRecordEntity::getDate, params.getCondition().getDateEnd());
        }
        IPage<YkfNotCheckRecordEntity> page = this.page(
                new Query<YkfNotCheckRecordEntity>().getPage(BeanUtil.beanToMap(params.getPage())),
                queryWrapper
        );
        if (ObjectUtil.isNotEmpty(page.getRecords())) {
            for (YkfNotCheckRecordEntity record : page.getRecords()) {
                YkfCustomerShopEntity shop = shopService.getById(record.getShopId());
                record.setEndDate(shop.getEndDate());
            }
        }
        return new PageUtils(page);
    }

}
